class Solution {
public:
    int maxIncreaseKeepingSkyline(vector<vector<int>>& grid)
    {
        //找每行每列最大 二者取小
        int ans = 0;
        vector<int> rowMax;
        vector<int> colMax;
        int n = grid.size();
        int m = grid[0].size();
        for (int i = 0; i < n; i++)
        {
            int mx = -1;
            for (int j = 0; j < m; j++)
                if (grid[i][j] > mx) mx = grid[i][j];
            rowMax.push_back(mx);
        }
        for (int i = 0; i < n; i++)
        {
            int mx = -1;
            for (int j = 0; j < m; j++)
                if (grid[j][i] > mx) mx = grid[j][i];
            colMax.push_back(mx);
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
                ans += min(colMax[j], rowMax[i]) - grid[i][j];
        }


        return ans;

    }
};